package com.rabbitmqdemo.eureka.service.impl;

import com.rabbitmqdemo.eureka.config.RabbitConfig;
import com.rabbitmqdemo.eureka.service.Producer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 生产者发送消息
 */

@Component
public class ProducerImpl implements Producer {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    RabbitTemplate rabbitTemplate;

    @Override
    public void sendMsg(String msg) {
        logger.info("收到发送消息的请求");
        rabbitTemplate.convertAndSend(RabbitConfig.EXCHANGE, RabbitConfig.ROUTINGKEY, msg);
        logger.info("已发送消息");
    }

}
